//
//  HomeViewModel.m
//  HonlivApp
//
//  Created by admin on 2017/6/23.
//  Copyright © 2017年 honliv. All rights reserved.
//

#import "HomeViewModel.h"
#import "CommonNews.h"

@implementation HomeViewModel

-(void)loadDataArray:(void (^)())success{
    NSString *dataPath = [[NSBundle mainBundle] pathForResource:@"Index" ofType:@"plist"];
    NSString *imgPath = [[NSBundle mainBundle] pathForResource:@"Images" ofType:@"plist"];
    
    _imageArray = [NSArray arrayWithContentsOfFile:imgPath];
    _dataArray = [NSArray arrayWithContentsOfFile:dataPath];
    
    //公司新闻：{db:"apilkoa",SqlNo:"19",Page:"1"}
    NSDictionary *info = @{@"db":@"apilkoa",@"SqlNo":@"19",@"Page":@"1"};
    NSString *url = [NSString stringWithFormat:@"%@%@",HOSPITAL_URL,COMMON_URL];
    [NetWorker getCommonDatasWithURLStr:url body:info success:^(id result) {
        NSString *arrayStr = result[@"Entity"];
        NSMutableArray *modelArr = [NSMutableArray array];
        NSArray *news = [JsonHelper arrayWithJsonString:arrayStr];
        for (NSDictionary *dic in news) {
            CommonNews *news = [CommonNews yy_modelWithDictionary:dic];
            [modelArr addObject:news];
        }
        _newsArray = [NSArray arrayWithArray:modelArr];
        
        success();
    } failure:^(id result) {
        [SVProgressHUD showErrorWithStatus:@"暂无新闻推荐"];
    }];

}



@end
